<?php

namespace App\Models;

class WithdrawModel
{
    /**
     * 获取用户提现列表
     * return Array
     * */
    public static function getUserWithdrawListInside($conn,$WithdrawExample){
        $querySql="SELECT `id`, `uid`, `serial`, `name`, `account`, `bank`,`money`,`amount`,`charge`,`type`,`time`,`stime`,`status`,`cause`,`genre` FROM `withdraw` WHERE  `uid` = '$WithdrawExample->uid' order by `time` desc limit 100";
        return $conn->readConn($querySql,true);
    }
    /**
     * 获取用户提现列表(id索引)
     * return Array
     * */
    public static function getUserWithdrawInsideInid($conn,$id){
        $querySql="SELECT `id`, `uid`, `serial`, `name`, `account`, `bank`,`money`,`amount`,`charge`,`type`,`time`,`stime`,`status`,`cause`,`genre` FROM `withdraw` WHERE  `id` = $id";
        return $conn->readConn($querySql);
    }
    /**
     * 获取用户提现成功总金额
     * return Array
     * */
    public static function getUserWithdrawSuccessMoneyInside($conn,$uid){
        $querySql="SELECT sum(`money`) as money FROM `withdraw` WHERE  `uid` = '$uid' and `status` = 2";
        return $conn->readConn($querySql);
    }
    /**
     * 获取用户提现中总金额
     * return Array
     * */
    public static function getUserWithdrawMiddleMoneyInside($conn,$uid){
        $querySql="SELECT sum(`money`) as money FROM `withdraw` WHERE  `uid` = '$uid' and `status` = 1";
        return $conn->readConn($querySql);
    }
    /**
     * 插入提现信息
     * entry conn,token
     * return int
     * */
    public static function insertWithdrawInside($conn,$WithdrawExample){
        $insertSql = "insert into `withdraw`(`uid`,`serial`,`money`,`amount`,`charge`)value($WithdrawExample->uid,'$WithdrawExample->serial',$WithdrawExample->money,$WithdrawExample->amount,$WithdrawExample->charge)";
        return $conn->executeConn($insertSql);
    }
    /**
     * 编辑提现
     * entry $WithdrawExample
     * return int
     * */
    public static function editWithdrawInside($conn,$WithdrawExample){
        $joinSql="";
        if($WithdrawExample->cause !=null){
            $joinSql.=" `cause` = '$WithdrawExample->cause',";
        }
        if($WithdrawExample->status !=null){
            $joinSql.=" `status` = $WithdrawExample->status,";
        }
        if($joinSql !=null){
            $innerJoin = rtrim($joinSql,",");
            $upUserSql="UPDATE  `withdraw` SET $innerJoin WHERE `id` =$WithdrawExample->id";
            return $conn->executeConn($upUserSql);
        }
    }
}